package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.MgtGoodPeopleThings;
import com.ruoyi.bussiness.service.IMgtGoodPeopleThingsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 好人好事Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/things")
public class MgtGoodPeopleThingsController extends BaseController
{
    private String prefix = "bussiness/things";

    @Autowired
    private IMgtGoodPeopleThingsService mgtGoodPeopleThingsService;

    @RequiresPermissions("bussiness:things:view")
    @GetMapping()
    public String things()
    {
        return prefix + "/things";
    }

    /**
     * 查询好人好事列表
     */
    @RequiresPermissions("bussiness:things:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MgtGoodPeopleThings mgtGoodPeopleThings)
    {
        startPage();
        List<MgtGoodPeopleThings> list = mgtGoodPeopleThingsService.selectMgtGoodPeopleThingsList(mgtGoodPeopleThings);
        return getDataTable(list);
    }

    /**
     * 导出好人好事列表
     */
    @RequiresPermissions("bussiness:things:export")
    @Log(title = "好人好事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MgtGoodPeopleThings mgtGoodPeopleThings)
    {
        List<MgtGoodPeopleThings> list = mgtGoodPeopleThingsService.selectMgtGoodPeopleThingsList(mgtGoodPeopleThings);
        ExcelUtil<MgtGoodPeopleThings> util = new ExcelUtil<MgtGoodPeopleThings>(MgtGoodPeopleThings.class);
        return util.exportExcel(list, "好人好事数据");
    }

    /**
     * 新增好人好事
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存好人好事
     */
    @RequiresPermissions("bussiness:things:add")
    @Log(title = "好人好事", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MgtGoodPeopleThings mgtGoodPeopleThings)
    {
        return toAjax(mgtGoodPeopleThingsService.insertMgtGoodPeopleThings(mgtGoodPeopleThings));
    }

    /**
     * 修改好人好事
     */
    @RequiresPermissions("bussiness:things:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MgtGoodPeopleThings mgtGoodPeopleThings = mgtGoodPeopleThingsService.selectMgtGoodPeopleThingsById(id);
        mmap.put("mgtGoodPeopleThings", mgtGoodPeopleThings);
        return prefix + "/edit";
    }

    /**
     * 修改保存好人好事
     */
    @RequiresPermissions("bussiness:things:edit")
    @Log(title = "好人好事", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MgtGoodPeopleThings mgtGoodPeopleThings)
    {
        return toAjax(mgtGoodPeopleThingsService.updateMgtGoodPeopleThings(mgtGoodPeopleThings));
    }

    /**
     * 删除好人好事
     */
    @RequiresPermissions("bussiness:things:remove")
    @Log(title = "好人好事", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mgtGoodPeopleThingsService.deleteMgtGoodPeopleThingsByIds(ids));
    }
}
